package estates.facade;

import estates.model.*;
import estates.persist.controller.*;
import javax.faces.context.FacesContext;
import java.util.List;

public class Fasada2 {
    private EstateController estateController;
    private UserController userController;
    private CommentController commentController;

    public Fasada2() {
        FacesContext fc = FacesContext.getCurrentInstance();
        estateController = (EstateController)fc.getApplication().getELResolver().getValue(fc.getELContext(), null, "estateJpa");
        userController = (UserController)fc.getApplication().getELResolver().getValue(fc.getELContext(), null, "userJpa");
        commentController = (CommentController)fc.getApplication().getELResolver().getValue(fc.getELContext(), null, "commentJpa");
    }

    public List<Comment> listComments() {
      return commentController.list();
    }

    public void persistComment(Comment entity) {
      try {
        commentController.create(entity);
      } catch (Exception e) {}
    }

    public List<Estate> listEstates() {
        return estateController.list();
    }

    public void persistEstate(Estate entity) {
        try {
            estateController.create(entity);
        } catch (Exception e) {}
    }

    public List<User> listUsers() {
        return userController.list();
    }

    public void persistUser(User entity) {
        try {
            userController.create(entity);
        } catch (Exception e) {}
    }
}
